
/********************************************************************/
/********************************************************************/
///*** The Incentives of Leaders in International Organizations: ***///
///***       Evidence from the UN General Assembly          *********///
/********************************************************************/
/********************************************************************/



/*****************************************************************/
///***     Figure 1 Timeline ***///
/*****************************************************************/

clear
use estimation_file

sort iso3n year
by year, sort: egen demleader=mean(executive) if vdem==1
by year, sort: egen nodemleader=mean(executive) if vdem==0
replace demleader= demleader*100
replace nodemleader= nodemleader*100
by year, sort: egen numleader=mean(executive)
replace numleader= numleader*100


graph twoway  line numleader year , yaxis(1) lpattern(solid) lwidth(medthick) lcolor(black)  || ///
line demleader year,   lpattern(shortdash)   || ///
line nodemleader year, lpattern(solid)   lcolor(gs12) lwidth(thin)  yaxis(1) ///
xlabel(1945(5)2020,  valuelabel angle(45)) ///
ylabel(0(10)60, axis(1) valuelabel angle(360)) ///
ytitle("Percentage", axis(1)) ///
plotregion(margin(r+1 t+0.5)) ///
xtitle("Year") ytitle("Percentage of speakers")   scheme(s1mono)  ///
legend(on order(1 "All" 2 "Democracy" 3 "Dictatorship")  ///
 size(medsize) region(lcolor(white)) rows(1) ) 
graph export output/timeline_all_regimes.pdf, replace

drop numleader demleader nodemleader
clear


/*****************************************************************/
///***  Table 1: Countries that Send Their Leaders Most and Least ***///
/*****************************************************************/

clear
use estimation_file
keep country executive
drop if executive==0
collapse (sum) executive, by(country)
sort executive
/* only top and bottom countries from the list are displayed */


/*****************************************************************/
///***  Figure 1: Countries and Their Heads of State at the UN, Globally ***///
/*****************************************************************/

/* create a file for making a map */
clear
use estimation_file
gen leader=executive
gen iso3n2=iso3n
replace iso3n2=643 if iso3n2==810
replace iso3n2=203 if iso3n2==200
replace iso3n2=729 if iso3n2==736
replace iso3n2=834 if iso3n2==835
replace iso3n2=887 if iso3n2==886
replace iso3n2=688 if iso3n2==890
replace iso3n2=158 if iso3n2==0
collapse (mean) leader, by(iso3n2)
/* present as per cent */
gen leader2=leader*100
saveold output/leaders_map, replace version(12)

/* run Figure1_map.R in R to replicate Figure 1 */



/**********************************************************************************/
/* Table 2 Prestige, Domestic Considerations, and Leaders at the UN       */
/**********************************************************************************/

clear
use estimation_file


xtlogit executive  worldrulerl1   lastterm divided  v2xnp_pres communist     _spline1 _spline2 _spline3   , re
est store m1
xtlogit executive  worldrulerl1  divided  lastterm v2xnp_pres  communist  loggdpsize logdistcap emergency  member  anniv   globalevent  _spline1 _spline2 _spline3  , re
est store m2
xtlogit executive  worldrulerl1  divided  lastterm  v2xnp_pres communist  loggdpsize logdistcap emergency  member  anniv   globalevent   _spline1 _spline2 _spline3   , fe
est store m3
 xtgee executive  worldrulerl1  divided  lastterm  v2xnp_pres communist   loggdpsize logdistcap emergency  member  anniv   globalevent  _spline1 _spline2 _spline3, i(ccode) ///
 t(year) corr(exchangeable) family(binomial) link(logit) vce(robust)
 est store m4
 xtlogit executive  worldrulerl1  divided  lastterm v2xnp_pres  communist  loggdpsize logdistcap emergency  member  anniv  globalevent post2000  _spline1 _spline2 _spline3, re
est store m5
xtlogit executive  worldrulerl1  divided  lastterm v2xnp_pres  communist  loggdpsize logdistcap emergency  member  anniv  globalevent   _spline1 _spline2 _spline3  if year<2000, re
est store m6
xtlogit executive  worldrulerl1  divided  lastterm v2xnp_pres  communist   loggdpsize logdistcap emergency  member  anniv  globalevent   _spline1 _spline2 _spline3  if year>2000, re
est store m7
xtlogit executive  worldrulerl1 divided  lastterm   _spline1 _spline2 _spline3  if vdem==1    , re
est store m8
xtlogit executive  worldrulerl1 divided  lastterm   emergency   member loggdpsize  anniv  logdistcap globalevent  _spline1 _spline2 _spline3   if vdem==1,  re
est store m9
xtlogit executive worldrulerl1 v2xnp_pres  communist   _spline1 _spline2 _spline3  if vdem==0, re
est store m10
xtlogit executive worldrulerl1 v2xnp_pres   emergency   logdistcap member loggdpsize   anniv communist globalevent _spline1 _spline2 _spline3  if vdem==0, re
est store m11
xtlogit executive  logpop log10income worldrulerl1  divided  lastterm  v2xnp_pres communist   _spline1 _spline2 _spline3   , re
est store m12			 
xtlogit executive  intercareer minforeign foreignedu leaderage worldrulerl1 log10income divided  lastterm  v2xnp_pres communist   _spline1 _spline2 _spline3   , re
est store m13			 			
xtlogit executive  anywar  e_migdpgro  worldrulerl1  divided  lastterm  log10income v2xnp_pres communist    _spline1 _spline2 _spline3   , re
est store m14
estout  m1 m2  m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  style(tex) legend label varlabels(_cons Constant) stats(N N_g ll chi2 sigma_u rho, fmt(0 0 2 3) ///
label(N Ncountries Log-likelihood chi2 sigma_u rho)) starlevels(+ 0.10 ** 0.05 *** 0.001) 



/**********************************************************************************/
/* Figure 3  top  */
/**********************************************************************************/


clear
use estimation_file		 
gen pipe = "|"
gen where = .001
			 
xtlogit executive  c.worldrulerl1  divided  lastterm v2xnp_pres    loggdpsize logdistcap emergency  member  anniv      communist globalevent  _spline1 _spline2 _spline3   , re

margins, at(worldruler=(5(5)60)) 


marginsplot, recast(line) recastci(rcap) ///
ylab( 0 "0" .2 "20" .4 "40" .6 "60" .8 "80"  , labsize(small) angle(360))   ysize(4) xsize(5) scheme(s1mono) ///
             ytitle("Probability of individual attendance", size(small)) plotregion(margin(t-10)) ///
			 xlab(10 "10" 25 "25" 40 "45" 55 "55"  , labsize(small)) plotregion(margin(t-10))  ///
			 xtitle("Percentage of world leaders attending last year", size(small)) title("All leaders", size(medsmall ))   ///
			 addplot((scatter where worldrulerl1,  ///
			 xlab() msymbol(none) mlabel(pipe) mlabposition(0)), below) legend(off)
graph export output/margins_all.pdf, replace		 
			 
/* estimate to discuss in text */			 
xtlogit executive worldrulerl1 v2xnp_pres  communist   _spline1 _spline2 _spline3  if vdem==0, re
margins , at(v2xnp_pres=(0 0.5 1)) grand atmeans predict(pr)	
		
	
//*************************************************************//
///******  Figure 3 left bottom  **************///
//*************************************************************//



clear
use estimation_file
xtlogit executive  worldrulerl1 divided  lastterm   emergency   member loggdpsize  anniv  logdistcap globalevent  _spline1 _spline2 _spline3   if vdem==1,  re
margins, dydx(*)  post
parmest, saving(output/m1, replace) 
clear
use output/m1
drop in 10/12
ren parm vars

replace vars="Emergency session year" if vars=="emergency"
replace vars="Lame duck" if vars=="lastterm"
replace vars="GDP, log" if vars=="loggdpsize"
replace vars="Divided government" if vars=="divided"
replace vars="IO membership" if vars=="member"
replace vars="Anniversary year" if vars=="anniv"
replace vars="Geographic distance" if vars=="logdistcap"
replace vars="Communist regime" if vars=="communist"
replace vars="Leaders attending" if vars=="worldrulerl1"
replace vars="Power concentration" if vars=="v2xnp_pres"
replace vars="Global events" if vars=="globalevent"



replace estimate=estimate*100
replace min95=min95*100
replace max95=max95*100 
gsort -estimate
sencode vars, gen(var)

 twoway (rcap min max var,  lcolor(black) lwidth(0.1) horizontal)  ///
     ||  (scatter var estimate, msymbol(d) mfcolor(white) msize(small)), ///
ylabel(1 2 3 4 5 6 7 8 9 , valuelabel angle(0) labsize(small ) )  ///
 ytitle("") xtitle("")  xscale(titlegap(*5)) scheme(s1mono) ///
xline(0, lwidth(0.001) lcolor(gray) lpattern(dash))  ///
title("Democratic leaders", size(medsmall ))  xlabel(-20(10)10, labsize(small)) ///
 plotregion(margin( t+0 b+0))  legend(off) ysize(4) xsize(4)  
graph export output/margins_dem.pdf, replace

clear



//*************************************************************//
///******  Figure 3 right bottom **************///
//*************************************************************//

clear
use estimation_file
xtlogit executive worldrulerl1 v2xnp_pres   emergency   logdistcap member loggdpsize   anniv communist globalevent _spline1 _spline2 _spline3  if vdem==0, re
margins, dydx(*)  post
parmest, saving(output/m2, replace) 
clear
use output/m2
drop in 10/12
ren parm vars
replace vars="Emergency session year" if vars=="emergency"
replace vars="Lame duck" if vars=="lastterm"
replace vars="GDP, log" if vars=="loggdpsize"
replace vars="Divided government" if vars=="divided"
replace vars="IO membership" if vars=="member"
replace vars="Anniversary year" if vars=="anniv"
replace vars="Geographic distance" if vars=="logdistcap"
replace vars="Communist regime" if vars=="communist"
replace vars="Leaders attending" if vars=="worldrulerl1"
replace vars="Power concentration" if vars=="v2xnp_pres"
replace vars="Global events" if vars=="globalevent"


replace estimate=estimate*100
replace min95=min95*100
replace max95=max95*100 
gsort -estimate
sencode vars, gen(var)


 twoway (rcap min max var,  lcolor(black) lwidth(0.05) horizontal)  ///
     ||  (scatter var estimate, msymbol(d) mfcolor(white) msize(small)), ///
ylabel(1 2 3 4 5 6 7 8 9 , valuelabel angle(0) labsize(small ) )  yscale(alt) ///
 ytitle("") xtitle("")  xscale(titlegap(*5)) scheme(s1mono) ///
xline(0, lwidth(0.001) lcolor(gray) lpattern(dash))  ///
title("Nondemocratic leaders", size(medsmall )) xlabel(-20(10)10, labsize(small)) ///
 plotregion(margin(l-0 r-0 t+0 b+0))  legend(off) ysize(4) xsize(4)  
graph export output/margins_nondem.pdf, replace		
		

/*****************************************************************/
///***     Table 3: Interrupted Times Series       ***///
/*****************************************************************/

clear
use output/splines
mkspline break1 1960 break2 1990 break3 2000 break4 2005 break5 = year

gen time = _n
gen y1960=0
gen y1990=0
gen y2000=0
gen y2005=0
replace y1960=1 if year==1961
replace y1990=1 if year==1991
replace y2000=1 if year==2001
replace y2005=1 if year==2006


reg worldruler time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant 
est store m1
reg regionruler1 time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant 
est store m3
reg regionruler2 time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant 
est store m4
reg regionruler3 time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant 
est store m5
reg regionruler4 time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant 
est store m6
reg regionruler5 time y1960 break2 y1990 break3 y2000 break4  y2005 break5,  noconstant  
est store m7

estout m1  m3 m4 m5 m6 m7, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))   legend label varlabels(_cons constant)   ///
 stats(N r2 , fmt(0  2 3) label(N R-squared )) style(tex) starlevels(+ 0.10 ** 0.05 *** 0.001)


 
 
  
